<template>
  <div>
    <!-- 头部 -->
    <div class="profile-box">
      <van-image round fit="cover" :src="userInfo.photo" />
      <div class="info-box">
        <div class="name">{{ userInfo.name }}</div>
        <div class="birthday">{{ userInfo.birthday }}</div>
      </div>
    </div>
    <!-- 中间宫格 -->
    <van-grid :column-num="3" :border="false">
      <van-grid-item
        style="color: #3296fa"
        icon="newspaper-o"
        text="我的作品"
      />
      <van-grid-item style="color: #f00" icon="star-o" text="我的收藏" />
      <van-grid-item style="color: orange" icon="tosend" text="阅读历史" />
    </van-grid>
    <!-- 下边儿cell -->
    <van-cell-group>
      <van-cell to="/mine/edit" title="编辑资料" icon="edit" is-link />
      <van-cell to="/mine/chat" title="小智同学" icon="chat-o" is-link />
      <van-cell title="系统设置" icon="setting-o" is-link />
      <van-cell @click="logout" title="退出登录" icon="info-o" is-link />
    </van-cell-group>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import { Dialog } from 'vant'
export default {
  name: 'MyMine',
  computed: {
    ...mapState('user', ['userInfo'])
  },
  created () {
    this.$store.dispatch('user/reqSetInfo')
  },
  methods: {
    logout () {
      Dialog.confirm({
        title: '退出',
        message: '确定退出吗？'
      })
        .then(() => {
          // on confirm
          this.$store.commit('user/setToken', {})
          this.$toast('退出成功')
          this.$router.push('/login')
        })
        .catch(() => {
          // on cancel
        })
    }
  }
}
</script>

<style lang="less" scoped>
.profile-box {
  @bgc: #3296fa;
  background-color: @bgc;
  height: 140px;
  display: flex;
  align-items: center;
  .van-image {
    width: 120px;
    height: 120px;
    margin: 15px 20px 8px;
  }
  .info-box {
    .name {
      font-size: 20px;
      color: #fff;
      margin-bottom: 10px;
    }
    .birthday {
      background-color: #fff;
      color: @bgc;
      padding: 5px 3px;
    }
  }
}
</style>
